<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body>
    <div id="app">
        {{user.age}}
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            user: {}
        },
        created(){
            //发送一个get请求
            /**
             * 一部分是发送请求axios.get("/user/add.do?id=1&name=itcast")
             * 一部分是正常得到结果.then()
             * 一部分是异常（后端报错了）结果catch()
             */
            axios.get("/user/add.do?id=1&name=itcast").then((response) =>{
                //得到的响应结果会放入到response变量的data属性中
                if(response.data.flag){
                    this.user = response.data.data;
                }else{
                    this.$message.error("异常了");
                }
            }).catch((error) => {
               console.log(error);
            });

            axios.get("/user/add.do",{params:{id:1,name:itcast}}).then().catch();

            axios.post("/user/add.do?age=20&address=南京",{id:1,name:itcast}).then().catch();
            axios.delete("/user/delete.do?id=1").then().catch();
        }
    });

</script>
</html>